home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 008 / cadence.arc / VOL1NO6.ARC / CHGTEXT.LSP next >
Encoding:
Text File  |  1980-01-01  |  2.0 KB  |  52 lines

  1. ; ----------------------------------------------------------------------------
  2. ;
  3. ;   CADENCE6    Recursion Examples              Bill Kramer 10/86
  4. ;
  5. ;
  6. ;   Recursive routine: CHANGE-TEXT
  7. ;   Seach for a substring in a string, replace all occurances with
  8. ;   with a new string.
  9. ;
  10. (defun change-text (olds news strng)
  11.    (cond
  12.       ((= olds (substr strng 1 (strlen olds)))
  13.           (strcat
  14.               news (change-text olds news (substr strng (1+ (strlen olds)))))) 
  15.       ((= (strlen strng) 0) strng)
  16.       (t (strcat (substr strng 1 1)
  17.                  (change-text olds news (substr strng 2))))))
  18. ; -----------------------------------------------------------
  19. ;
  20. ;   Function: CHG-TEXT
  21. ;   Show text entities to be changed, enter change strings and
  22. ;   execute CHANGE-TEXT for each string.
  23. ;
  24. (defun c:chg-text ()
  25.    (prompt "\nSelect text entities:")
  26.    (setq ss nil) (gc) ; Clear the selection set.
  27.    (setq ss (ssget)) ; Enter the items
  28.    (setq olds (getstring "\nOld string value:"))
  29.    (setq news (getstring "\nNew string value:"))
  30.    (setq cnt 0 cmax (sslength ss)) ; Set up loop variables
  31.    (while (< cnt cmax) ; Go through all of the selection set entities
  32.       (setq ename (ssname ss cnt)) ; Get the next entity name from set
  33.       (setq elist (entget ename)) ; Get the entity list.
  34.       (cond
  35.         ((= (cdr (assoc 0 elist)) "TEXT")  ; List is text?
  36.            (setq chgs (change-text olds news (cdr (assoc 1 elist))))
  37.            (cond
  38.              ((/= chgs (cdr (assoc 1 elist))) ; Text changed?
  39.                  (setq elist (subst (cons 1 chgs) (assoc 1 elist) elist))
  40.                  (entmod elist))))) ; Redisplay list.
  41.       (setq cnt (1+ cnt))))
  42. ; -------------------------------
  43. ;
  44. ;   Draw several insertions of a figure,
  45. ;   Rotation and scaling is iteratively increased.
  46. ;
  47. (defun fungraphs (fig scl rot dscl drot insp cnt)
  48.    (command "INSERT" fig insp scl "" rot)
  49.    (cond 
  50.       ((> cnt 0)
  51.         (fungraphs fig (+ scl dscl) (+ rot drot) dscl drot insp (1- cnt)))))
  52.